﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;
namespace Yugi.Client.ViewModel
{
    public  partial class MainServerHandler
    {
        List<object> ConvertReciveMainServer_L_Recurrence_Table_OK(byte[] param)
        {
            List<byte> input = param.ToList();
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 0, param.Length).Split('|');
            foreach (var i in tmp)
                res.Add(i);
            return res;
        }
        List<object> ConvertReciveMainServer_L_Update_JoinRoom_OK(byte[] param)
        {
            List<byte> input = param.ToList();
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 0, param.Length).Split('|');
            foreach (var i in tmp)
                res.Add(i);
            return res;
        }
        List<object> ConvertReciveMainServer_L_Update_OutRoom_OK(byte[] param)
        {
            List<byte> input = param.ToList();
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 0, param.Length).Split('|');
            foreach (var i in tmp)
                res.Add(i);
            return res;
        }
        List<object> ConvertReciveMainServer_L_Login_OK(byte[] param)
        {
            List<object> res = new List<object>();
            res.Add((int)param[0]);
            return res;
        }
        List<object> ConvertReciveMainServer_L_Update_Friend_OK(byte[] param)
        {
            List<object> res = new List<object>();
            res.Add((int)param[0]);
            return res;
        }
        List<object> ConvertReciveMainServer_L_Update_Friend_Off_OK(byte[] param)
        {
            List<object> res = new List<object>();
            res.Add((int)param[0]);
            return res;
        }
        List<object> ConvertReciveMainServer_L_Login_Failed(byte[] param)
        {
            List<object> res = new List<object>();
            
            return res;
        }
        List<object> ConvertReciveMainServer_L_Get_List_Table(byte[] param)
        {
            List<object> res = new List<object>();
            
            return res;
        }
        List<object> ConvertReciveMainServer_L_CreateTable_OK(byte[] param)
        {
            List<byte> input = param.ToList();
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 0, param.Length).Split(':');
            string[] tmp2 = tmp[0].Split('|');
            foreach (var i in tmp2)
                res.Add(i);
            res.Add(tmp[1]);
            res.Add(tmp[2]);
            return res;
        }
        List<object> ConvertReciveMainServer_L_JoinTable_OK(byte[] param)
        {
            List<byte> input = param.ToList();
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 0, param.Length).Split(':');
            string[] tmp2 = tmp[0].Split('|');
            foreach (var i in tmp2)
                res.Add(i);
            res.Add(tmp[1]);
            res.Add(tmp[2]);
            return res;
        }
        List<object> ConvertReciveMainServer_L_OutTable_OK(byte[] param)
        {
            List<byte> input = param.ToList();
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 0, param.Length).Split('|');
            foreach (var i in tmp)
                res.Add(i);
            return res;
        }
        List<object> ConvertReciveMainServer_L_CreateRoom_OK(byte[] param)
        {
            List<byte> input = param.ToList();
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 0, param.Length).Split('|');
            foreach (var i in tmp)
                res.Add(i);
            return res;
        }
        List<object> ConvertReciveMainServer_L_JoinRoom_OK(byte[] param)
        {
            List<byte> input = param.ToList();
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 0, param.Length).Split('|');
            foreach (var i in tmp)
                res.Add(i);
            return res;
        }
        List<object> ConvertReciveMainServer_L_OutRoom_OK(byte[] param)
        {
            List<byte> input = param.ToList();
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 0, param.Length).Split('|');
            foreach (var i in tmp)
                res.Add(i);
            return res;
        }
        List<object> ConvertReciveMainServer_L_Update_Error(byte[] param)
        {
            List<object> res = new List<object>();
            return res;
        }

        //chat
        List<object> ConvertReciveMainServer_L_Chat_Channel(byte[] param)
        {
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 1, param.Length - 1).Split(':');
            res.Add(tmp[0]);
            res.Add(tmp[1]);
            res.Add(tmp[2]);
            return res;
        }
        
        List<object> ConvertReciveMainServer_L_Chat_OK(byte[] param)
        {
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 1, param.Length - 1).Split(':');
            res.Add(tmp[0]);
            res.Add(tmp[1]);
            res.Add(tmp[2]);
            return res;
        }

        List<object> ConvertReciveMainServer_L_Chat_Error(byte[] param)
        {
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 1, param.Length - 1).Split(':');
            res.Add(tmp[0]);
            res.Add(tmp[1]);
            res.Add(tmp[2]);
            return res;
        }

        //list user online
        List<object> ConvertReciveMainServer_L_User_On(byte[] param)
        {
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 1, param.Length - 1).Split(':');
            res.Add(tmp[0]);
            res.Add(tmp[1]);
            return res;
        }

        List<object> ConvertReciveMainServer_L_User_Off(byte[] param)
        {
            List<object> res = new List<object>();
            string tmp = Encoding.UTF8.GetString(param, 1, param.Length - 1);
            res.Add(tmp);
            return res;
        }

        List<object> ConvertReciveMainServer_L_User_AllOn(byte[] param)
        {
            List<object> res = new List<object>();
            string[] tmp = Encoding.UTF8.GetString(param, 1, param.Length - 1).Split(':');
            res.AddRange(tmp);
            res.RemoveAt(res.Count - 1);
            return res;
        }

        //--------------------------Send---------------------------------//
        byte[] ConvertSendMainServer_L_Login(object[] param)
        {
            string format = param[0].ToString() + ":" + param[1].ToString();
            return UTF8Encoding.UTF8.GetBytes(format);
        }
        byte[] ConvertSendMainServer_L_CreateTable(object[] param)
        {
            List<byte> temp = new List<byte>();
            temp.AddRange(BitConverter.GetBytes((int)param[0]));
            return temp.ToArray();
        }
        byte[] ConvertSendMainServer_L_CreateRoom(object[] param)
        {
            string format = param[0].ToString();
            return UTF8Encoding.UTF8.GetBytes(format);
        }
        byte[] ConvertSendMainServer_L_JoinTable(object[] param)
        {
            List<byte> temp = new List<byte>();
            temp.AddRange(BitConverter.GetBytes((int)param[0]));
            return temp.ToArray();
        }
        byte[] ConvertSendMainServer_L_JoinRoom(object[] param)
        {
            List<byte> temp = new List<byte>();
            temp.AddRange(BitConverter.GetBytes((int)param[0]));
            return temp.ToArray();
        }
        byte[] ConvertSendMainServer_L_JoinRoomF(object[] param)
        {
            List<byte> temp = new List<byte>();
            temp.AddRange(BitConverter.GetBytes((int)param[0]));
            return temp.ToArray();
        }
        byte[] ConvertSendMainServer_L_OutTable(object[] param)
        {
            List<byte> temp = new List<byte>();
            temp.AddRange(BitConverter.GetBytes((int)param[0]));
            return temp.ToArray();
        }
        byte[] ConvertSendMainServer_L_OutRoom(object[] param)
        {
            List<byte> temp = new List<byte>();
            temp.AddRange(BitConverter.GetBytes((int)param[0]));
            return temp.ToArray();
        }
        byte[] ConvertSendMainServer_L_Update_Card(object[] param)
        {
            List<byte> temp = new List<byte>();
            List<int> Data = (List<int>)param[0];
            temp.Add((byte)(int)Data.Count);
            for (int i = 0; i < temp[0]; i++)
            {
                temp.Add((byte)(int)Data[i]);
            }
            return temp.ToArray();
        }

        // CHAT
        byte[] ConvertSendMainServer_L_Chat_Channel(object[] param)
        {
            string format = param[0].ToString() + ":" + param[1].ToString() + ":" + param[2].ToString();
            return UTF8Encoding.UTF8.GetBytes(format);
        }
        byte[] ConvertSendMainServer_L_Chat_OK(object[] param)
        {
            string format = param[0].ToString() + ":" + param[1].ToString() + ":" + param[2].ToString();
            return UTF8Encoding.UTF8.GetBytes(format);
        }

        //list user
        byte[] ConvertSendMainServer_L_User_AllOn(object[] param)
        {
            string format = param[0].ToString();
            return UTF8Encoding.UTF8.GetBytes(format);
        }

    }
}
